package cn.itsource.feign.fallback;

import cn.itsource.doc.CourseDoc;
import cn.itsource.feign.client.ESFeignClient;
import cn.itsource.hrm.query.CourseQuery;
import cn.itsource.hrm.utils.AjaxResult;
import cn.itsource.hrm.utils.PageList;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class ESFeignClientFactory implements FallbackFactory<ESFeignClient> {
    @Override
    public ESFeignClient create(Throwable throwable) {
        return new ESFeignClient() {
            @Override
            public AjaxResult onLineCourse(CourseDoc courseDoc) {
                //托底方法 报错返回提示
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("搜索服务不可用？");
            }

            @Override
            public AjaxResult offLineCourse(Long id) {
                //托底方法 报错返回提示
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("搜索服务不可用？");
            }

            @Override
            public PageList<CourseDoc> searchCourse(CourseQuery courseQuery) {
                throwable.printStackTrace();
                //条数为-1，走拖地了
                return new PageList<>(-1,new ArrayList<>());            }
        };
    }
}
